students = {}

while True:
    print("\n===== 学生成绩管理系统 =====")
    print("1. 添加学生 2. 删除学生 3. 查询所有成绩 4. 查询单科成绩 5. 查看排名 0. 退出")
    choice = input("请选择：")

    if choice == '1':
        name = input("姓名：")
        students[name] = {subj: float(input(f"{subj}成绩："))
                          for subj in input("科目列表（逗号分隔）：").split(',')}
        print(f"添加成功：{name}")

    elif choice == '2':
        name = input("要删除的学生姓名：")
        print(f"删除成功：{name}" if students.pop(name, None) else "学生不存在")

    elif choice == '3':
        name = input("要查询的学生姓名：")
        if name in students:
            print(f"{name}成绩：" + ', '.join(f"{s}:{g}" for s, g in students[name].items()))
            print(f"总分：{sum(students[name].values())}")
        else:
            print("学生不存在")

    elif choice == '4':
        name, subj = input("学生姓名,科目：").split(',')
        print(f"{subj}成绩：{students[name][subj]}" if name in students and subj in students[name] else "成绩不存在")

    elif choice == '5':
        print("\n".join(f"{i + 1}. {n}: 总分{sum(s.values())}"
                        for i, (n, s) in enumerate(sorted(students.items(), key=lambda x: -sum(x[1].values()))))
              if students else "暂无数据")

    elif choice == '0':
        print("再见！")
        break

    else:
        print("无效选择")